package com.google.wave.api.samples;

import java.net.MalformedURLException;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

import org.apache.log4j.Logger;

public class UrlFetcher {
	private static Logger log = Logger.getLogger(UrlFetcher.class);

	public static String fetchUrl(String anUrl) {

		StringBuilder response = new StringBuilder();

		try {
			URL url = new URL(anUrl);
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					url.openStream()));
			String line;

			while ((line = reader.readLine()) != null) {
				response.append(line);
			}
			reader.close();

		} catch (MalformedURLException e) {
				log.error("Malformed url: "  + anUrl + " Msg:"  + e.getMessage() );
		} catch (IOException e) {
			log.error("Io exception... url: "  + anUrl + " Msg:"  + e.getMessage() );
		}
		return response.toString();
	}

}
